﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Media;
using MSPToolkit.Models;
using System.Windows.Controls;
using System.Windows.Shapes;

namespace MSPToolkit.Utilities
{
    public static class TileImageGenerator
    {
        private const string BasicPath = "/Shared/ShellContent/";
        private const short ThreeDigitsBackgroundImageMargin = 3;
        private const short TwoDigitsBackgroundImageMargin = 8;
        private const short OneDigitBackgroundImageMargin = 13;
        private const short ThreeDigitsNumberMargin = 94;
        private const short TwoDigitsNumberMargin = 104;
        private const short SingleDigitNumberMargin = 114;
        private const string MaxNumberValue = "999";

        private static Dictionary<TileSize,Size> _tileSize = new Dictionary<TileSize,Size>()
        { 
                {MSPToolkit.Utilities.TileSize.Wp7TileSize, new Size(173, 173)},
                {MSPToolkit.Utilities.TileSize.Wp8SmallTileSize, new Size(159, 159)},
                {MSPToolkit.Utilities.TileSize.Wp8TileSize, new Size(336, 336)},
                {MSPToolkit.Utilities.TileSize.Wp8WideTileSize, new Size(691, 336)},
        };

        private static Dictionary<TileSize, Size> _mosaicImageSize = new Dictionary<TileSize, Size>()
        { 
                {MSPToolkit.Utilities.TileSize.Wp7TileSize, new Size(57.67, 57.67)},
                {MSPToolkit.Utilities.TileSize.Wp8SmallTileSize, new Size(53, 53)},
                {MSPToolkit.Utilities.TileSize.Wp8TileSize, new Size(112, 112)},
                {MSPToolkit.Utilities.TileSize.Wp8WideTileSize, new Size(115.17, 112)},
        };

        /// <summary>
        /// Tile Image sizes
        /// </summary>
        public static Dictionary<TileSize, Size> TileSize { get { return _tileSize; } }

        /// <summary>
        /// Size of one image on mosaic (3*3)
        /// </summary>
        public static Dictionary<TileSize, Size> MosaicImageSize { get { return _mosaicImageSize; } }

        /// <summary>
        /// Renders an integer number on the live tile as on message tile
        /// </summary>
        /// <param name="uri">Uri of the background image</param>
        /// <param name="number">Number that would be rendered</param>
        /// <param name="imageName">Name of the live tile image file</param>
        /// <param name="size">Size of tile</param>
        /// <param name="imageFormat">Image format</param>
        /// <returns>Uri to the image file</returns>
        public static Uri GenerateTile(Uri uri, uint number, string tileImageName, TileSize size = Utilities.TileSize.Wp7TileSize)
        {
            uri.ThrowExceptionIfArgumentIsNull("uri");
            tileImageName.ThrowExceptionIfArgumentIsNull("tileImageName");

            var k = TileSize[size].Height / TileSize[Utilities.TileSize.Wp7TileSize].Height;

            var BackgroundImage = new UriWithTransform { Uri = uri, Width = 120 * k, Height = 120 * k, TranslateTransform = new TranslateTransform { X = IsSingleDigit(number) ? OneDigitBackgroundImageMargin * k : IsTwoDigit(number) ? TwoDigitsBackgroundImageMargin * k : ThreeDigitsBackgroundImageMargin * k, Y = 25 * k } };

            var text = new StringsWithTransform
            {
                Text = number.ToString().Length > 3 ? MaxNumberValue : number.ToString(),
                FontFamily = (FontFamily)Application.Current.Resources["PhoneFontFamilySemiBold"],
                FontSize = 65 * k,
                TranslateTransform = new TranslateTransform { X = IsSingleDigit(number) ? SingleDigitNumberMargin * k : IsTwoDigit(number) ? TwoDigitsNumberMargin * k : ThreeDigitsNumberMargin * k, Y = 42 * k }
            };
            List<ImageWithTransform> img = new List<ImageWithTransform> { ImageGenerator.UriToImageWithTransform(BackgroundImage) };
            var url = ImageGenerator.GenerateImageBase(new List<TextBlockWithTransform> { ImageGenerator.StringToTextBlockWithTransform(text) }, img, tileImageName, (int)_tileSize[size].Width, (int)_tileSize[size].Height);
            img.Clear();
            return url;
        }

        /// <summary>
        /// Renders a collection of Images on the live tile
        /// </summary>
        /// <param name="images">Images that would be rendered</param>
        /// <param name="imageName">Name of the generating image</param>
        /// <param name="size">Size of tile</param>
        /// <param name="imageFormat">Image format</param>
        /// <returns>Uri to the image file</returns>
        public static Uri GenerateTile(IEnumerable<ImageWithTransform> images, string tileImageName, TileSize size = Utilities.TileSize.Wp7TileSize, ImageFormat imageFormat = ImageFormat.Png)
        {
            images.ThrowExceptionIfArgumentIsNull("images");
            tileImageName.ThrowExceptionIfArgumentIsNull("tileImageName");

            return ImageGenerator.GenerateImageBase(new List<TextBlockWithTransform>(), images, tileImageName, (int)_tileSize[size].Width, (int)_tileSize[size].Height, imageFormat);
        }

        /// <summary>
        /// Renders a collection of  strings on the live tile
        /// </summary>
        /// <param name="strings">Strings that would be rendered</param>
        /// <param name="imageName">Name of the generating image</param>
        /// <param name="size">Size of tile</param>
        /// <param name="imageFormat">Image format</param>
        /// <returns>Uri to the image file</returns>
        public static Uri GenerateTile(IEnumerable<StringsWithTransform> strings, string tileImageName, TileSize size = Utilities.TileSize.Wp7TileSize, ImageFormat imageFormat = ImageFormat.Png)
        {
            strings.ThrowExceptionIfArgumentIsNull("strings");
            tileImageName.ThrowExceptionIfArgumentIsNull("tileImageName");

            var textBlocks = strings.Select(ImageGenerator.StringToTextBlockWithTransform);
            IEnumerable<ImageWithTransform> img = new List<ImageWithTransform>();
            return ImageGenerator.GenerateImageBase(textBlocks, img , tileImageName, (int)_tileSize[size].Width, (int)_tileSize[size].Height, imageFormat);
        }

        /// <summary>
        /// Renders a collection of TextBlocks on the live tile
        /// </summary>
        /// <param name="textBlocks">Text blocks that would be rendered</param>
        /// <param name="imageName">Name of the generating image</param>
        /// <param name="size">Size of tile</param>
        /// <param name="imageFormat">Image format</param>
        /// <returns>Uri to the image file</returns>
        public static Uri GenerateTile(IEnumerable<TextBlockWithTransform> textBlocks, string tileImageName, TileSize size = Utilities.TileSize.Wp7TileSize, ImageFormat imageFormat = ImageFormat.Png)
        {
            textBlocks.ThrowExceptionIfArgumentIsNull("textBlocks");
            tileImageName.ThrowExceptionIfArgumentIsNull("tileImageName");
            IEnumerable<ImageWithTransform> img = new List<ImageWithTransform>();
            return ImageGenerator.GenerateImageBase(textBlocks, img, tileImageName, (int)_tileSize[size].Width, (int)_tileSize[size].Height, imageFormat);
        }

        /// <summary>
        /// Renders a collection of Images from URIs on the live tile
        /// </summary>
        /// <param name="uris">URIs that would be rendered</param>
        /// <param name="imageName">Name of the generating image</param>
        /// <param name="size">Size of tile</param>
        /// <param name="imageFormat">Image format</param>
        /// <returns>Uri to the image file</returns>
        public static Uri GenerateTile(IEnumerable<UriWithTransform> uris, string tileImageName, TileSize size = Utilities.TileSize.Wp7TileSize, ImageFormat imageFormat = ImageFormat.Png)
        {
            uris.ThrowExceptionIfArgumentIsNull("uris");
            tileImageName.ThrowExceptionIfArgumentIsNull("tileImageName");

            return ImageGenerator.GenerateImageBase(new List<TextBlockWithTransform>(), uris.Select(ImageGenerator.UriToImageWithTransform), tileImageName, (int)_tileSize[size].Width, (int)_tileSize[size].Height, imageFormat);
        }

        /// <summary>
        /// Renders a collection of TextBlocks and Images from URIs on the live tile
        /// </summary>
        /// <param name="uris">URIs that would be rendered</param>
        /// <param name="imageName">Name of the generating image</param>
        /// <param name="size">Size of tile</param>
        /// <param name="imageFormat">Image format</param>
        /// <returns>Uri to the image file</returns>
        public static Uri GenerateTile(IEnumerable<TextBlockWithTransform> textBlocks, IEnumerable<UriWithTransform> uris, string tileImageName, TileSize size = Utilities.TileSize.Wp7TileSize, ImageFormat imageFormat = ImageFormat.Png)
        {
            textBlocks.ThrowExceptionIfArgumentIsNull("textBlocks");
            uris.ThrowExceptionIfArgumentIsNull("uris");
            tileImageName.ThrowExceptionIfArgumentIsNull("tileImageName");

            return ImageGenerator.GenerateImageBase(textBlocks, uris.Select(ImageGenerator.UriToImageWithTransform), tileImageName, (int)_tileSize[size].Width, (int)_tileSize[size].Height, imageFormat);
        }

        /// <summary>
        /// Renders two graphs on the live tile for usual or small tile or up to three for wide tile
        /// </summary>
        /// <param name="data">Source data</param>
        /// <param name="legends">Legend data</param>
        /// <param name="tileImageName">Name of the generating image</param>
        /// <param name="size">Size of tile</param>
        /// <param name="imageFormat">Image format</param>
        /// <returns>Uri to the image file</returns>
        public static Uri GenerateGraphOnTile(List<List<double>> data, List<string> legends, string tileImageName, TileSize size = Utilities.TileSize.Wp7TileSize, ImageFormat imageFormat = ImageFormat.Png)
        {
            data.ThrowExceptionIfArgumentIsNull("data");
            legends.ThrowExceptionIfArgumentIsNull("legends");

            var graphAmount = data.Count();
            if (graphAmount > 2)
                throw new ArgumentOutOfRangeException("data");
            if (legends.Count > 2)
                throw new ArgumentOutOfRangeException("legends", "Legends list has more than 2 elements");

            var mainCanvas = new Canvas() { Width = _tileSize[size].Width, Height = TileSize[size].Height };
            
            

            var graphStep = size != Utilities.TileSize.Wp8SmallTileSize ? TileSize[size].Height / (data.Count + 2) : TileSize[size].Height / (data.Count + 1);
            double widthStep = 0;

            for (int graphIndex = 0; graphIndex < data.Count; graphIndex++)
            {
                var graphCanvas = data[graphIndex];
                if (graphCanvas.Count > 7)
                    throw new ArgumentOutOfRangeException("legends", "More than 7 elements on the sub list");

                graphCanvas = ConvertToPositiveValues(graphCanvas);
                graphCanvas = Normalize(graphCanvas, graphStep);

                widthStep = size != Utilities.TileSize.Wp8SmallTileSize ? (TileSize[size].Width - TileSize[size].Height / 5) / (graphCanvas.Count) : TileSize[size].Width / (graphCanvas.Count + 1);

                var canvasGraph = new Canvas { Width = TileSize[size].Width, Height = graphStep };
                
                for (int elementIndex = 0; elementIndex < graphCanvas.Count(); elementIndex++)
                {
                    if (elementIndex > 0)
                    {
                        var line = new Line
                        {
                            Y1 = canvasGraph.Height - graphCanvas.ElementAt(elementIndex - 1),
                            Y2 = canvasGraph.Height - graphCanvas.ElementAt(elementIndex),
                            X1 = (elementIndex - 1) * widthStep,
                            X2 = elementIndex * widthStep,
                            Stroke = new SolidColorBrush(Colors.White),
                            StrokeThickness = 5
                        };
                        canvasGraph.Children.Add(line);
                    }

                    var dot = new Ellipse() { Width = TileSize[size].Height / 20, Height = TileSize[size].Height / 20, Fill = new SolidColorBrush(Colors.White), };
                    Canvas.SetLeft(dot, elementIndex * widthStep - dot.Width / 2);
                    Canvas.SetTop(dot, canvasGraph.Height - graphCanvas.ElementAt(elementIndex) - dot.Height / 2);
                    canvasGraph.Children.Add(dot);
                }

                var legendString = legends[graphIndex];
                if (legendString != null && size != Utilities.TileSize.Wp8SmallTileSize)
                {
                    var legent = new TextBlock { Text = legendString, Foreground = new SolidColorBrush(Colors.White), FontSize = TileSize[size].Height / 12 };
                    Canvas.SetLeft(legent, TileSize[size].Width - TileSize[size].Height / 5 - widthStep / 2);
                    Canvas.SetTop(legent, graphStep / 2 - legent.FontSize);
                    canvasGraph.Children.Add(legent);
                }

                Canvas.SetLeft(canvasGraph, widthStep / 2);
                Canvas.SetTop(canvasGraph, graphStep*(graphIndex+0.5));
                mainCanvas.Children.Add(canvasGraph);
            }

            return ImageGenerator.GenerateImageBase(mainCanvas, tileImageName, (int)_tileSize[size].Width, (int)_tileSize[size].Height, imageFormat);
        }

        private static List<double> ConvertToPositiveValues(List<double> points)
        {
            var min = points.Min();

            return points.Select(p => p -= min).ToList();
        }

        private static List<double> Normalize(List<double> points, double maxValue)
        {
            var max = points.Max();

            return points.Select(p => (p / max) * maxValue).ToList();
        }

        /// <summary>
        /// Renders a collection of TextBlocks and Images on the live tile
        /// </summary>
        /// <param name="textBlocks">TextBlocks that would be rendered</param>
        /// <param name="images">Images that would be rendered</param>
        /// <param name="imageName">Name of the generating image</param>
        /// <param name="imageFormat">Tile image format</param>
        /// <param name="imageFormat">Image format</param>
        /// <returns>Uri to the image file</returns>
        public static Uri GenerateTile(IEnumerable<TextBlockWithTransform> textBlocks, IEnumerable<ImageWithTransform> images, string tileImageName, TileSize size = Utilities.TileSize.Wp7TileSize, ImageFormat imageFormat = ImageFormat.Png)
        {
            textBlocks.ThrowExceptionIfArgumentIsNull("textBlocks");
            images.ThrowExceptionIfArgumentIsNull("images");
            tileImageName.ThrowExceptionIfArgumentIsNull("tileImageName");

            return ImageGenerator.GenerateImageBase(textBlocks, images, tileImageName, (int)_tileSize[size].Width, (int)_tileSize[size].Height, imageFormat);
        }

        /// <summary>
        /// Renders images as a mosaic on tile
        /// </summary>
        /// <param name="imageUri1">Uri for the image on the 1*1 place</param>
        /// <param name="imageUri2">Uri for the image on the 1*2 place</param>
        /// <param name="imageUri3">Uri for the image on the 1*3 place</param>
        /// <param name="imageUri4">Uri for the image on the 2*1 place</param>
        /// <param name="imageUri5">Uri for the image on the 2*2 place</param>
        /// <param name="imageUri6">Uri for the image on the 2*3 place</param>
        /// <param name="imageUri7">Uri for the image on the 3*1 place</param>
        /// <param name="imageUri8">Uri for the image on the 3*2 place</param>
        /// <param name="imageUri9">Uri for the image on the 3*3 place</param>
        /// <param name="imageName">Name of the live tile image file</param>
        /// <param name="imageFormat">Image format</param>
        /// <returns>Uri to the image file</returns>
        public static Uri GenerateTile(Uri imageUri1, Uri imageUri2, Uri imageUri3, Uri imageUri4, Uri imageUri5, Uri imageUri6, Uri imageUri7, Uri imageUri8, Uri imageUri9, string tileImageName, TileSize size = Utilities.TileSize.Wp7TileSize, ImageFormat imageFormat = ImageFormat.Png)
        {
            imageUri1.ThrowExceptionIfArgumentIsNull("imageUri1");
            imageUri2.ThrowExceptionIfArgumentIsNull("imageUri2");
            imageUri3.ThrowExceptionIfArgumentIsNull("imageUri3");
            imageUri4.ThrowExceptionIfArgumentIsNull("imageUri4");
            imageUri5.ThrowExceptionIfArgumentIsNull("imageUri5");
            imageUri6.ThrowExceptionIfArgumentIsNull("imageUri6");
            imageUri7.ThrowExceptionIfArgumentIsNull("imageUri7");
            imageUri8.ThrowExceptionIfArgumentIsNull("imageUri8");
            imageUri9.ThrowExceptionIfArgumentIsNull("imageUri9");
            tileImageName.ThrowExceptionIfArgumentIsNull("tileImageName");
            if (size == Utilities.TileSize.Wp8WideTileSize)
            {
                throw new ArgumentException("Not support wide tile for 9 images use 18 images overload", "size");
            }

            var mosaicImageSize = MosaicImageSize[size];

            var uriList = new List<UriWithTransform>
            {
                new UriWithTransform{ Uri = imageUri1, Width = mosaicImageSize.Width, Height = mosaicImageSize.Height, TranslateTransform=new TranslateTransform()},
                new UriWithTransform{ Uri = imageUri2, Width = mosaicImageSize.Width, Height = mosaicImageSize.Height, TranslateTransform=new TranslateTransform(){ X = mosaicImageSize.Width }},
                new UriWithTransform{ Uri = imageUri3, Width = mosaicImageSize.Width, Height = mosaicImageSize.Height, TranslateTransform=new TranslateTransform(){ X = 2 * mosaicImageSize.Width }},
                new UriWithTransform{ Uri = imageUri4, Width = mosaicImageSize.Width, Height = mosaicImageSize.Height, TranslateTransform=new TranslateTransform(){ Y = mosaicImageSize.Height }},
                new UriWithTransform{ Uri = imageUri5, Width = mosaicImageSize.Width, Height = mosaicImageSize.Height, TranslateTransform=new TranslateTransform(){ Y = mosaicImageSize.Height, X = mosaicImageSize.Width }},
                new UriWithTransform{ Uri = imageUri6, Width = mosaicImageSize.Width, Height = mosaicImageSize.Height, TranslateTransform=new TranslateTransform(){ Y = mosaicImageSize.Height, X = 2 * mosaicImageSize.Width }},
                new UriWithTransform{ Uri = imageUri7, Width = mosaicImageSize.Width, Height = mosaicImageSize.Height, TranslateTransform=new TranslateTransform(){ Y = 2 * mosaicImageSize.Height }},
                new UriWithTransform{ Uri = imageUri8, Width = mosaicImageSize.Width, Height = mosaicImageSize.Height, TranslateTransform=new TranslateTransform(){ Y = 2 * mosaicImageSize.Height, X = mosaicImageSize.Width }},
                new UriWithTransform{ Uri = imageUri9, Width = mosaicImageSize.Width, Height = mosaicImageSize.Height, TranslateTransform=new TranslateTransform(){ Y = 2 * mosaicImageSize.Height, X = 2 * mosaicImageSize.Width }}
            };

            return ImageGenerator.GenerateImageBase(new List<TextBlockWithTransform>(), uriList.Select(ImageGenerator.UriToImageWithTransform), tileImageName, (int)_tileSize[size].Width, (int)_tileSize[size].Height, imageFormat);
        }

        /// <summary>
        /// Renders images as a mosaic on wide tile
        /// </summary>
        /// <param name="imageUri1">Uri for the image on the 1*1 place</param>
        /// <param name="imageUri2">Uri for the image on the 1*2 place</param>
        /// <param name="imageUri3">Uri for the image on the 1*3 place</param>
        /// <param name="imageUri4">Uri for the image on the 2*1 place</param>
        /// <param name="imageUri5">Uri for the image on the 2*2 place</param>
        /// <param name="imageUri6">Uri for the image on the 2*3 place</param>
        /// <param name="imageUri7">Uri for the image on the 3*1 place</param>
        /// <param name="imageUri8">Uri for the image on the 3*2 place</param>
        /// <param name="imageUri9">Uri for the image on the 3*3 place</param>
        /// <param name="imageUri1">Uri for the image on the 1*4 place</param>
        /// <param name="imageUri2">Uri for the image on the 1*5 place</param>
        /// <param name="imageUri3">Uri for the image on the 1*6 place</param>
        /// <param name="imageUri4">Uri for the image on the 2*4 place</param>
        /// <param name="imageUri5">Uri for the image on the 2*5 place</param>
        /// <param name="imageUri6">Uri for the image on the 2*6 place</param>
        /// <param name="imageUri7">Uri for the image on the 3*4 place</param>
        /// <param name="imageUri8">Uri for the image on the 3*5 place</param>
        /// <param name="imageUri9">Uri for the image on the 3*6 place</param>
        /// <param name="imageName">Name of the live tile image file</param>
        /// <param name="imageFormat">Image format</param>
        /// <returns>Uri to the image file</returns>
        public static Uri GenerateTile(Uri imageUri1, Uri imageUri2, Uri imageUri3, Uri imageUri4, Uri imageUri5, Uri imageUri6, Uri imageUri7, Uri imageUri8, Uri imageUri9,
                                       Uri imageUri10, Uri imageUri11, Uri imageUri12, Uri imageUri13, Uri imageUri14, Uri imageUri15, Uri imageUri16, Uri imageUri17, Uri imageUri18,
                                       string tileImageName, ImageFormat imageFormat = ImageFormat.Png)
        {
            imageUri1.ThrowExceptionIfArgumentIsNull("imageUri1");
            imageUri2.ThrowExceptionIfArgumentIsNull("imageUri2");
            imageUri3.ThrowExceptionIfArgumentIsNull("imageUri3");
            imageUri4.ThrowExceptionIfArgumentIsNull("imageUri4");
            imageUri5.ThrowExceptionIfArgumentIsNull("imageUri5");
            imageUri6.ThrowExceptionIfArgumentIsNull("imageUri6");
            imageUri7.ThrowExceptionIfArgumentIsNull("imageUri7");
            imageUri8.ThrowExceptionIfArgumentIsNull("imageUri8");
            imageUri9.ThrowExceptionIfArgumentIsNull("imageUri9");
            imageUri10.ThrowExceptionIfArgumentIsNull("imageUri10");
            imageUri11.ThrowExceptionIfArgumentIsNull("imageUri11");
            imageUri12.ThrowExceptionIfArgumentIsNull("imageUri12");
            imageUri13.ThrowExceptionIfArgumentIsNull("imageUri13");
            imageUri14.ThrowExceptionIfArgumentIsNull("imageUri14");
            imageUri15.ThrowExceptionIfArgumentIsNull("imageUri15");
            imageUri16.ThrowExceptionIfArgumentIsNull("imageUri16");
            imageUri17.ThrowExceptionIfArgumentIsNull("imageUri17");
            imageUri18.ThrowExceptionIfArgumentIsNull("imageUri18");
            tileImageName.ThrowExceptionIfArgumentIsNull("tileImageName");

            var mosaicImageSize = MosaicImageSize[Utilities.TileSize.Wp8WideTileSize];

            var uriList = new List<UriWithTransform>
            {
                new UriWithTransform{ Uri = imageUri1, Width = mosaicImageSize.Width, Height = mosaicImageSize.Height, TranslateTransform=new TranslateTransform()},
                new UriWithTransform{ Uri = imageUri2, Width = mosaicImageSize.Width, Height = mosaicImageSize.Height, TranslateTransform=new TranslateTransform(){ X = mosaicImageSize.Width }},
                new UriWithTransform{ Uri = imageUri3, Width = mosaicImageSize.Width, Height = mosaicImageSize.Height, TranslateTransform=new TranslateTransform(){ X = 2 * mosaicImageSize.Width }},
                new UriWithTransform{ Uri = imageUri4, Width = mosaicImageSize.Width, Height = mosaicImageSize.Height, TranslateTransform=new TranslateTransform(){ Y = mosaicImageSize.Height }},
                new UriWithTransform{ Uri = imageUri5, Width = mosaicImageSize.Width, Height = mosaicImageSize.Height, TranslateTransform=new TranslateTransform(){ Y = mosaicImageSize.Height, X = mosaicImageSize.Width }},
                new UriWithTransform{ Uri = imageUri6, Width = mosaicImageSize.Width, Height = mosaicImageSize.Height, TranslateTransform=new TranslateTransform(){ Y = mosaicImageSize.Height, X = 2 * mosaicImageSize.Width }},
                new UriWithTransform{ Uri = imageUri7, Width = mosaicImageSize.Width, Height = mosaicImageSize.Height, TranslateTransform=new TranslateTransform(){ Y = 2 * mosaicImageSize.Height }},
                new UriWithTransform{ Uri = imageUri8, Width = mosaicImageSize.Width, Height = mosaicImageSize.Height, TranslateTransform=new TranslateTransform(){ Y = 2 * mosaicImageSize.Height, X = mosaicImageSize.Width }},
                new UriWithTransform{ Uri = imageUri9, Width = mosaicImageSize.Width, Height = mosaicImageSize.Height, TranslateTransform=new TranslateTransform(){ Y = 2 * mosaicImageSize.Height, X = 2 * mosaicImageSize.Width }},
                new UriWithTransform{ Uri = imageUri11, Width = mosaicImageSize.Width, Height = mosaicImageSize.Height, TranslateTransform=new TranslateTransform(){ X = 3 * mosaicImageSize.Width }},
                new UriWithTransform{ Uri = imageUri11, Width = mosaicImageSize.Width, Height = mosaicImageSize.Height, TranslateTransform=new TranslateTransform(){ X = 4 * mosaicImageSize.Width }},
                new UriWithTransform{ Uri = imageUri12, Width = mosaicImageSize.Width, Height = mosaicImageSize.Height, TranslateTransform=new TranslateTransform(){ X = 5 * mosaicImageSize.Width }},
                new UriWithTransform{ Uri = imageUri13, Width = mosaicImageSize.Width, Height = mosaicImageSize.Height, TranslateTransform=new TranslateTransform(){ Y = mosaicImageSize.Height, X = 3 * mosaicImageSize.Width }},
                new UriWithTransform{ Uri = imageUri14, Width = mosaicImageSize.Width, Height = mosaicImageSize.Height, TranslateTransform=new TranslateTransform(){ Y = mosaicImageSize.Height, X = 4 * mosaicImageSize.Width }},
                new UriWithTransform{ Uri = imageUri15, Width = mosaicImageSize.Width, Height = mosaicImageSize.Height, TranslateTransform=new TranslateTransform(){ Y = mosaicImageSize.Height, X = 5 * mosaicImageSize.Width }},
                new UriWithTransform{ Uri = imageUri16, Width = mosaicImageSize.Width, Height = mosaicImageSize.Height, TranslateTransform=new TranslateTransform(){ Y = 2 * mosaicImageSize.Height, X = 3 * mosaicImageSize.Width }},
                new UriWithTransform{ Uri = imageUri17, Width = mosaicImageSize.Width, Height = mosaicImageSize.Height, TranslateTransform=new TranslateTransform(){ Y = 2 * mosaicImageSize.Height, X = 4 * mosaicImageSize.Width }},
                new UriWithTransform{ Uri = imageUri18, Width = mosaicImageSize.Width, Height = mosaicImageSize.Height, TranslateTransform=new TranslateTransform(){ Y = 2 * mosaicImageSize.Height, X = 5 * mosaicImageSize.Width }}
            };

            return ImageGenerator.GenerateImageBase(new List<TextBlockWithTransform>(), uriList.Select(ImageGenerator.UriToImageWithTransform), tileImageName, (int)_tileSize[Utilities.TileSize.Wp8WideTileSize].Width, (int)_tileSize[Utilities.TileSize.Wp8WideTileSize].Height, imageFormat);
        }

        /// <summary>
        /// Returns does the number contain only one digit
        /// </summary>
        /// <param name="number">Number that would be checked</param>
        /// <returns>Does the number contain only one digit</returns>
        private static bool IsSingleDigit(uint number)
        {
            return number >= 0 && number < 10;
        }

        /// <summary>
        /// Returns does the number contain two digits
        /// </summary>
        /// <param name="number">Number that would be checked</param>
        /// <returns>Does the number contain  two digits</returns>
        private static bool IsTwoDigit(uint number)
        {
            return number >= 10 && number < 100;
        }


        
    }

    public enum TileSize
    {
        Wp7TileSize,
        Wp8TileSize,
        Wp8SmallTileSize,
        Wp8WideTileSize
    }
}